﻿/// <reference path="lib/jquery1.4.2.min.js" />
$(function ()
{
    if ($("#TBcon").length > 0)
    {
        var support = $("#support");
        $("#TBcon img[s]").css("cursor", "pointer")
            .mouseover(function ()
            {
                if ($(this).attr("s"))
                {
                    var support = $("#support");
                    var left = document.body.scrollLeft | document.documentElement.scrollLeft;
                    var top = document.body.scrollTop | document.documentElement.scrollTop;
                    support.css("left", this.getBoundingClientRect().left + left);
                    support.css("top", this.getBoundingClientRect().top + top + 18);
                    support.show();
                    support.html('<img src="images/loading.gif" />');
                    $.post("/XHR/LoadSupport.ashx", { u: $(this).attr("s") }, function (data)
                    {
                        support.html(data);
                    });
                }
            })
            .mouseout(function ()
            {
                support.fadeOut(600);
            });
            support.mouseleave(function ()
            {
                support.empty().hide();
            });
            support.mouseover(function ()
            {
                support.stop().fadeTo(1, 1);
            });
    }
}
);


/// 加载下拉列表  ///
//s：名称（提交表单的id为 s ,下拉列表分别为s1, s2 ,s3 等，加载默认值dv1 dv2 dv3...)
//v：上级ID值
//n：当前下拉列表数量++
//p：是否添加 请选择 选项
//t：为新增下拉列表的默认值
function loadselect(s, v, n, p, t)
{
    var Tval = $("#" + s);
    var Pselect = Tval.parent();
    var len = Pselect.children().length;
    for (var i = n; i < len; i++)
    {
        $("#" + s + i).remove();
    }
    if (v)
    {
        Tval.val(v);
        var tid;
        if (v == '0') tid = s + 1;
        else
        {
            tid = s + n;
            n++;
        }
        $.post("/XHR/LoadSelect.ashx", { t: s, id: v }, function (data)
        {
            if (data != "")
            {
                Pselect.append('<select id="' + tid + '"></select>');
                var Tselect = $('#' + tid);
                Tselect.change(function () { loadselect(s, this.value, n, p); });
                if (p) Tselect.append("<option value=''>请选择</option>");
                Tselect.append(data);
                if (t)
                {
                    $("#" + tid).val(t);
                    loadselect(s, t, n, p, Tval.attr("dv" + n));
                    Tval.removeAttr("dv" + n);
                    return;
                }
                if (!p)
                {
                    Tval.val(Tselect.val());
                    loadselect(s, Tselect.val(), n, 0);
                }
            }
        });
    }
    else
    {
        n = n - 2;
        if (n > 0) Tval.val($("#" + s + n).val());
        else Tval.val(0);
    }
}


///添加礼品（公司）收藏///
//t='g'时：添加礼品收藏
//t='c'时：添加公司收藏
function addFav(t, id)
{
    $.post("/XHR/fav.ashx", { t: t, id: id }, function (data)
    {
        if (data == "ok")
        {
            alert("添加收藏成功！");
        }
    });
}